{% extends "main.html" %}

{% block title %}Look at this feed{% endblock %}

{% block heading %}{{ url }}{% endblock %}

{% block init %}
	url = '{{url}}'
	if(url){
		google.feeds.lookupFeed(url, function(lookupResult){
			if(!lookupResult.error){
				feed = new google.feeds.Feed(lookupResult.url)
				feed.load(function(loadResult){
					if(!loadResult.error){
						entries = loadResult.feed.entries
						feedList = jQuery('#feed')
						for(var i=0; i < entries.length; i++){
							feedList.append("<li>"+entries[i].title+"</li>")
						}
					} else {
						alert(loadResult.error.message)
					}
				})
			} else {
				alert(lookupResult.error.message)
			}
		})
	} else {
		alert("gimme something to work with here")
	}
{% endblock %}

{% block content %}
	
	<table>
		<tr>
			<td>
				<p>If you created this feed claim it to automatically add it's entries to your interests</p>
				<form method="post" action="/feeds/{{ url} }/claim">
					<input type="button" name="action" value="Claim" />
				</form>
			</td>
			<td>
				<p>Add this feed to your reading list so you can mark which entries you are interested in.</p>
				<form method="post" action="/feeds/{{ url }}/subscribe">
					<input type="button" name="action" value="Subscribe" />
				</form>
			</td>
		</tr>
	</table>
	
	<ol id="feed"></ol>

{% endblock %}


